# -*- coding: utf-8 -*-

from app.module.admin import admin
from flask import render_template, request, session, jsonify
from app.module.admin.middleware import check_login
from app.service.common.member import Member as MemberService


@admin.route('/member/password', methods=['GET', 'POST'])
@check_login
def member_password():
    if request.method == 'POST':
        # 用 request.json 来接收 ajax 传过来的 json 数据
        rt = MemberService().change_pwd(
            session['member_id'],
            request.json['formPassword'],
            request.json['admin_password']
        )
        return jsonify(rt)
    return render_template('admin/member/password.html')
